﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<ProjectMeeting>
@{
    this.ViewBag.Title = "Projekter";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var locations = this.ViewData["Locations"] as List<Location> ?? new List<Location>();
    var projectMeetingTypes = this.ViewData["ProjectMeetingTypes"] as List<ProjectType> ?? new List<ProjectType>();
    var projectMeetingDemonstrations = this.ViewData["ProjectMeetingDemonstrations"] as List<ProjectMeetingDemonstration> ?? new List<ProjectMeetingDemonstration>();
    var projectMeetingRoles = this.ViewData["ProjectMeetingRoles"] as List<ProjectMeetingRole> ?? new List<ProjectMeetingRole>();
    DefaultSearchFields defaultFields = this.ViewData["DefaultFields"] as DefaultSearchFields ?? new DefaultSearchFields();
    var criteriaLocation = this.ViewData["CriteriaLocation"] as Guid?;
    var criteriaProjectType = this.ViewData["CriteriaProjectType"] as Guid?;
    var criteriaProjectDemonstration = this.ViewData["CriteriaProjectDemonstration"] as Guid?;
    var criteriaProjectRole = this.ViewData["CriteriaProjectRole"] as Guid?;
    var criteriaStatusType = this.ViewData["CriteriaStatusType"] as ProjectMeetingStatusType? ?? ProjectMeetingStatusType.None;
}
<h2>Søgeresultat - @ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    
        <tr>
            <td>Type:</td><td>@ViewBag.Title</td>
        </tr>
        <tr><td>Antal resultater i alt: </td><td>@Model.TotalRows</td></tr>
        @if (criteriaLocation.HasValue && criteriaLocation.Value != Guid.Empty)
        {
            <tr><td>Lokation: </td><td>@locations.Single(x => x.ID == criteriaLocation.Value).Name</td></tr>
        }
        
            <tr><td>Status: </td>
                <td>
                    @if (criteriaStatusType == ProjectMeetingStatusType.None){ @Html.Raw("Alle")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.NotStarted){ @Html.Raw("Ikke startet")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.Started){ @Html.Raw("Startet")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.Completed){ @Html.Raw("Færdigt")}
                    
                                 
                </td>
            </tr>
        
        
        @if (criteriaProjectType.HasValue && criteriaProjectType.Value != Guid.Empty)
        {
            var pt = projectMeetingTypes.Single(x => x.ID == criteriaProjectType.Value);
            <tr><td>Projekt type: </td><td>@Html.Raw(string.Format("({0}) {1}", pt.IsResearchAndDevelopment ? "R&D" : "Ikke R&D", pt.Name))</td></tr>
        }
        @if (criteriaProjectDemonstration.HasValue && criteriaProjectDemonstration.Value != Guid.Empty)
        {
            <tr><td>Demonstration: </td><td>@projectMeetingDemonstrations.Single(x => x.ID == criteriaProjectDemonstration.Value).Name</td></tr>
        }
        @if (criteriaProjectRole.HasValue && criteriaProjectRole.Value != Guid.Empty)
        {
            <tr><td>WT Rolle: </td><td>@projectMeetingRoles.Single(x => x.ID == criteriaProjectRole.Value).Name</td></tr>
        }
        @Html.Partial("~/Views/Reports/_SearchDefaultFieldsParametersTableTR.cshtml", defaultFields)

    </table>
</fieldset>


<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (ProjectMeeting meeting in this.Model.List)
        {
            List<Location> locs = locations.Where(x => x.ID == meeting.LocationID).ToList();
            Location location = locs.Count() > 0 ? locations[0] : null;
            <tr>
                <td>@string.Format("{0:dd-MM-yyyy}", meeting.Date)</td>
                <td>
                    @if (location != null)
                    {
                        @location.Name
                    }
                </td>
                <td>@meeting.Name</td>
                <td>@meeting.Status.Description</td>
                <td>
                    @if (meeting.Status.Type != Guid.Empty)
                    {
                        List<ProjectType> types = projectMeetingTypes.Where(x => x.ID == meeting.Status.Type).ToList();
                        if (types != null && types.Any())
                        {
                            @Html.Raw(string.Format("({0}) {1}", types[0].IsResearchAndDevelopment ? "R&D" : "Ikke R&D", types[0].Name))
                        }
                    }
                </td>
                <td>@meeting.Status.PatentName</td>
            </tr>
        }
    }
    </table>